
keep if year<=2010
keep if province<=9

*Excludes outlier observations
*This matters for RPP contributions because there are some amounts well above deduction limits
*This likely arises because the PA also includes payments to DPSPs
*The results are robust to other methods of controlling for outlier observations, such as truncation
gen out_sample=0
foreach x of varlist empinc rspcont rspwd penadj {
	summarize `x', detail
	replace out_sample=1 if `x'>r(p99)
}
keep if out_sample==0
drop out_sample

local counter=1991
gen contlimit=.
foreach x of numlist 11500 12500 12500 13500 14500 13500 13500 13500 13500 13500 13500 13500 15500 16500 18000 19000 20000 21000 22000 23000 {
	replace contlimit=`x' if year==`counter'
	local counter=`counter'+1
}

local counter=1991
gen cqppympe=.
foreach x of numlist 30500 32200 33400 34400 34900 35400 35800 36900 37400 37600 38300 39100 39900 40500 41100 42100 43700 44900 46300 47200 {
	replace cqppympe=`x' if year==`counter'
	local counter=`counter'+1
}

*Create various saving and control variables
gen agesq=age^2
tab yob, gen(cohort_)
tab year, gen(year_)
tab province, gen(province_)
gen union_flag=(dues>0)
gen empinc_flag=(empinc>0)
gen selfempinc_flag=(selfempinc>0)
gen rppempcont=penadj-rppcont
gen penadj_flag=(penadj>0)
gen rppcont_flag=(rppcont>0)
gen rspnetcont=rspcont-rspwd
gen rspcont_flag=(rspcont>0)
gen rspwd_flag=(rspwd>0)
gen saving=rspcont-rspwd+penadj
gen saverate=saving/ttlinc
gen unused=rspdlc-rspcont
gen unused_flag=(unused>0)
gen taxsave=invinc+capgain
gen nwsaving=rspnetcont+taxsave

gen eiinc_flag=(eiinc>0)
gen peninc_flag=(cqppben>0|peninc>0)
gen othinc=ttlinc-empinc
gen othinc2=ttlinc-empinc-invinc-capgain

*Centres income around the kink and creates the kink variable for lagged income
replace empinc=empinc-cqppympe
gen kink=(empinc>=0)
gen empinc_kink=empinc*kink

exit